import type { LoginResult } from '@/types/user'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const user = ref({} as LoginResult)
    const isLogin = ref(false)

    const setUser = (value: LoginResult) => {
      user.value = value
      isLogin.value = true
    }
    const removeUser = () => {
      isLogin.value = false
      user.value = {} as LoginResult
    }
    return {
      user,
      isLogin,
      setUser,
      removeUser,
    }
  },
  {
    persist: true,
  },
  // 自定义存储
  // {
  //   persist: {
  //     key: 'user',
  //     storage: localStorage,
  //     pick: ['user']
  //   }
  // }
)
